#include <iostream>
using namespace std;

class Person
{
public:
    int age;

    Person(int age)
    {
        // this指针指向 被调用的成员函数所属的对象
        this->age = age;
    }

    Person& PersonAddAge(Person& p)
    {
        this->age += p.age;
        return *this;
    }
};

//1、解决名称冲突
void test1()
{
    Person p1(18);

    cout << "p1的年龄为：" << p1.age << endl;
}

//2、返回对象本身用 *this
void test2()
{
    Person p1(10);

    Person p2(10);
    p2.PersonAddAge(p1).PersonAddAge(p1).PersonAddAge(p1);
    //链式编程思想
    
    cout << "p2的年龄为：" << p2.age << endl;
}

int main()
{
    test1();
    cout << "---------------" << endl;
    test2();
    return 0;
}